home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------
-
- Module: FIXED.H
-
- Class: Fixed
-
- Description:
-
-
- Revision History
- -----------------------------------------------------
- Date Name Comment
- -----------------------------------------------------
-
- Feb-16-93 rbf Added the addProduct function
-
- Nov-24-92 rbf Initial Creation
-
- ---------------------------------------------------*/
-
- #ifndef _FIXED_H
- #define _FIXED_H
-
- #if !defined(__IOSTREAM_H)
- #include <iostream.h>
- #endif
-
- typedef signed long FixedData;
-
- // construct a union of a Fixed
- // and two int sized parts
- // for easy access to the appropriate bits
-
- typedef union
- {
- FixedData long_rep;
- struct
- {
- unsigned int fractional_part;
- signed int whole_part;
- } half_rep;
- } FixedUnion;
-
-
- // Definition of class Fixed
- // in the Orthodox Canonical Form
-
- class Fixed
- {
-
- public: // Public interface to class
-
- // Boilerplate member functions
-
- // default constructor
- Fixed();
-
- // default copy constructor
- inline Fixed(const Fixed&);
-
- // default assignment
- inline Fixed& operator=(const Fixed&);
-
- // default destructor
- ~Fixed();
-
- // Class specific member functions & data
-
- friend ostream& operator<<
- ( ostream& s, Fixed& rhs );
-
- // various constructors & conversion operators
- // construct a Fixed from an int
- Fixed(int rhs);
- // construct a Fixed from an double or float
- Fixed(double rhs);
-
-
- // binary operators on a Fixed class
-
- friend Fixed operator-
- (const Fixed& lhs, const Fixed& rhs);
- friend Fixed operator+
- (const Fixed& lhs, const Fixed& rhs);
- friend Fixed operator*
- (const Fixed& lhs, const Fixed& rhs);
- friend Fixed operator/
- (const Fixed& lhs, const Fixed& rhs);
- friend int operator<
- (const Fixed& lhs, const Fixed& rhs);
- friend int operator>
- (const Fixed& lhs, const Fixed& rhs);
- friend int operator==
- (const Fixed& lhs, const Fixed& rhs);
- friend int operator!=
- (const Fixed& lhs, const Fixed& rhs);
- friend int operator<=
- (const Fixed& lhs, const Fixed& rhs);
- friend int operator>=
- (const Fixed& lhs, const Fixed& rhs);
-
- // unary operators on a Fixed class
- inline Fixed& operator+=(const Fixed& rhs);
- inline Fixed& operator-=(const Fixed& rhs);
- inline Fixed& operator*=(const Fixed& rhs);
- inline Fixed& operator/=(const Fixed& rhs);
- inline Fixed operator+ ();
- inline Fixed operator- ();
-
- void addProduct(const Fixed& rhs1,const Fixed& rhs2);
-
- protected: // Protected interface to class
-
- // Protected member functions & data
-
-
- private: // Private interface to class
-
- // Private member functions & data
- FixedUnion fixeddata;
-
-
- }; // Fixed
-
-
- #endif _FIXED_H
-